package com.lib.common.widget.adapter

import android.content.Context
import com.lib.common.R
import com.lib.common.databinding.ItemAvatarListBinding
import com.lib.common.utils.ImageLoadUtil
import com.lib.framework.widget.adapter.BaseBindingAdapter

/**
 * 头像列表的 adapter
 *
 * @author keanbin
 */
abstract class AvatarListAdapter<T>(context: Context, dataList: MutableList<T>) :
        BaseBindingAdapter<T, ItemAvatarListBinding>(context, dataList) {

    override fun getLayoutResId(viewType: Int): Int {
        return R.layout.item_avatar_list
    }

    override fun onBindItem(binding: ItemAvatarListBinding?, item: T, position: Int) {
        if (binding == null) {
            return
        }

        val avatarUrl = getAvatarUrl(item, position)
        ImageLoadUtil.load(avatarUrl, binding.ivAvatar, R.mipmap.ic_avatar02)
    }

    /**
     * 从数据中获得头像
     */
    abstract fun getAvatarUrl(item: T, position: Int): String
}